package com.guigu.qingcheng.orderservice.controller;


import com.guigu.qingcheng.orderservice.service.TbReturnCauseService;
import com.guigu.qingcheng.pojo.order.TbReturnCause;
import com.guigu.qingcheng.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("returncause")
public class TbReturnCauseController {
    @Autowired
    private TbReturnCauseService tbReturnCauseService;

    @GetMapping("findById")
    public R findById (Integer id) {
        TbReturnCause tbReturnCause = tbReturnCauseService.getById(id);
        if (tbReturnCause  == null)
            return R.error();
        return R.ok().data("tbReturnCause",tbReturnCause);
    }

    //查询分页查询
    @PostMapping("findPage")
    public R findPage (@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestBody(required = false) Map<String,Object> searchMap ) {
        return tbReturnCauseService.findPage(page, size, searchMap);
    }

    //新增
    @PostMapping("add")
    public R add (@RequestBody TbReturnCause tbReturnCause) {
        boolean save = tbReturnCauseService.save(tbReturnCause);
        if (save)
            return R.ok();
        return R.error();
    }

    //修改
    @PostMapping("update")
    public R update (@RequestBody TbReturnCause tbReturnCause) {
        boolean save = tbReturnCauseService.updateById(tbReturnCause);
        if (save)
            return R.ok();
        return R.error();
    }

    //删除
    @GetMapping("delete")
    public R delete (Integer id) {
        boolean save = tbReturnCauseService.removeById(id);
        if (save)
            return R.ok();
        return R.error();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @GetMapping("deletes")
    public R deletes (String ids) {
        return tbReturnCauseService.deletes(ids);
    }
}

